<template>
  <div class="mod-sp__spmatch">
    <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.matchId" placeholder="赛事ID" clearable></el-input>
      </el-form-item>
      <el-form-item label="地区" prop="province">
        <el-select style="width:150px" placeholder="请选择" v-model="dataForm.province"  @change="selectCity">
          <el-option value="" label="全国">全国</el-option>
          <el-option
            v-for="itemO in area.item"
            :key="itemO.code"
            :label="itemO.name"
            :value="itemO.code">
          </el-option>
        </el-select>
        ~
        <el-select style="width:150px" placeholder="请选择" v-model="dataForm.city" >
          <el-option value="" label="全部">全部</el-option>
          <el-option
            v-for="itemO in areaCity.item"
            :key="itemO.code"
            :label="itemO.name"
            :value="itemO.code">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column width="200" prop="matchName" label="赛事" header-align="center" align="center"></el-table-column>
      <el-table-column width="200" prop="teamName" label="代表队名称" header-align="center" align="center"></el-table-column>
      <el-table-column width="120" prop="company" label="代表队单位" header-align="center" align="center"></el-table-column>
      <el-table-column width="150" prop="leader" label="主领队姓名" header-align="center" align="center"></el-table-column>
      <el-table-column width="120" prop="phone" label="主领队电话" header-align="center" align="center"></el-table-column>
      <el-table-column width="120" prop="itemName" label="赛项" header-align="center" align="center"></el-table-column>
      <el-table-column width="120" prop="groupType" label="组别" header-align="center" align="center"></el-table-column>
      <el-table-column width="120" prop="groupName" label="队伍名称" header-align="center" align="center"></el-table-column>
      <el-table-column width="190" prop="realName" label="选手姓名" header-align="center" align="center"></el-table-column>
      <el-table-column width="190" prop="ranks" label="名次" header-align="center" align="center"></el-table-column>
      <el-table-column width="120" prop="grade" label="奖等" header-align="center" align="center"></el-table-column>
    </el-table>
    <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <!-- 字典类型数据 -->
    <el-drawer :title="focusDictTypeTitle" v-model="dictTypeListVisible" :size="800" close-on-press-escape="false" custom-class="rr-drawer"> <DictTypeList :dictTypeId="focusDictTypeId"></DictTypeList></el-drawer>
  </div>
</template>

<script lang="ts">
import useView from "@/hooks/useView";
import { defineComponent, reactive, toRefs } from "vue";
import AddOrUpdate from "./spmatch-add-or-update.vue";
import DictTypeList from "./spmatchitem.vue";
import {IObject} from "@/types/interface";
import baseService from "@/service/baseService";

export default defineComponent({
  components: {
    AddOrUpdate,
    DictTypeList
  },
  setup() {
    const state = reactive({
      getDataListURL: "/sp/spmatchitemteam/exportCerLog",
      getDataListIsPage: true,
      exportURL: "/sp/spmatchitemteam/exportCerLogExcel",
      deleteURL: "/sp/spmatch",
      deleteIsBatch: true,
      dataForm: {
        matchId: "",
        matchName: "",
        matchLevel: "",
        province: "",
        city: "",
        season: ""
      },
      dictTypeListVisible: false,
      focusDictTypeId: "",
      focusDictTypeTitle: "",
      area:{code:'0',item:[{code:'0',name:'请选择'}]},
      areaCity:{code:'0',item:[{code:'0',name:'请选择'}]},
    });
    return { ...useView(state), ...toRefs(state) };
  },
  watch: {
  },
  created() {
    this.areaList(this.area);
  },
  methods: {
    // 获取省份
    areaList(target: any) {
      baseService.get("/front/fast/sys/areaDict/list?pid=" + target.code).then((e: any) => {
        target.item = e.data;
      });
    },
    // 选择城市
    selectCity(){
      if(this.dataForm.province){
        this.areaCity.code=this.dataForm.province;
        this.areaList(this.areaCity);
      }else {
        this.dataForm.city = '';
        this.areaCity.item = [];
      }
    },
    showTypeList(row: IObject) {
      this.dictTypeListVisible = true;
      this.focusDictTypeId = row.id;
      this.focusDictTypeTitle = `${this.$route.meta.title}` +'-'+ row.matchName;
    }
  }

});
</script>
